package adapters;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.example.administrator.newxlmedical.GoodsDetialActivity;
import com.example.administrator.newxlmedical.InventoryActivity;
import com.example.administrator.newxlmedical.R;

import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.GoodsDetailInfoBean;
import beans.OperateGoodsDetailsBean;
import butterknife.BindView;
import constants.Constants;
import custom.BaseRecyclerAdapter;

/**
 * Created by Administrator on 2018/5/15.
 */

public class InventoryAdapter extends BaseRecyclerAdapter<InventoryAdapter.InventoryViewHolder> {
    private Context mContext;
    private LayoutInflater inflater;
    private List<OperateGoodsDetailsBean.DataBean> list;
    private PopupWindow popupWindow;

    public InventoryAdapter(Context mContext, List<OperateGoodsDetailsBean.DataBean> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
    }

    public void addData(List<OperateGoodsDetailsBean.DataBean> list) {
        if (list != null) {
            this.list.clear();
            this.list.addAll(list);
            notifyDataSetChanged();
        }
    }

    public List<OperateGoodsDetailsBean.DataBean> getList() {
        return list;
    }

    @Override
    public InventoryViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
        View inflate = inflater.inflate(R.layout.adapter_inventory, parent, false);
        InventoryViewHolder viewHolder = new InventoryViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final InventoryViewHolder viewHolder, final int position) {

        OperateGoodsDetailsBean.DataBean dataBean = list.get(position);
        viewHolder.tvGoodsName.setText(dataBean.getGoodName());
        viewHolder.tvSpecification.setText(dataBean.getSpecification());
        viewHolder.tvSupplier.setText(dataBean.getManufacturer());
        viewHolder.tvNumber.setText(String.valueOf(dataBean.getNumber()));
        viewHolder.tvCabinet.setText(dataBean.getLogicNumber());

        if (dataBean.getStatus() != 3 ){
            viewHolder.tvGoodsName.setTextColor(Color.RED);
            viewHolder.tvSpecification.setTextColor(Color.RED);
            viewHolder.tvNumber.setTextColor(Color.RED);
            viewHolder.tvCabinet.setTextColor(Color.RED);
        }else {
            viewHolder.tvGoodsName.setTextColor(mContext.getResources().getColor(R.color.textview_default_color));
            viewHolder.tvSpecification.setTextColor(mContext.getResources().getColor(R.color.textview_default_color));
            viewHolder.tvNumber.setTextColor(mContext.getResources().getColor(R.color.textview_default_color));
            viewHolder.tvCabinet.setTextColor(mContext.getResources().getColor(R.color.textview_default_color));
        }

        if (position % 2 == 0) {
            viewHolder.remindListRl.setBackgroundColor(mContext.getResources().getColor(R.color.partLineBackground));
        } else {
            viewHolder.remindListRl.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class InventoryViewHolder extends BaseRecyclerAdapter.BaseViewHolder {
        @BindView(R.id.remind_list_rl)
        LinearLayout remindListRl;
        @BindView(R.id.tv_adapter_cabinet)
        TextView tvCabinet;
        @BindView(R.id.tv_adapter_log_detail_goods_name)
        TextView tvGoodsName;
        @BindView(R.id.tv_adapter_log_detail_specification)
        TextView tvSpecification;
        @BindView(R.id.tv_adapter_log_detail_supplier)
        TextView tvSupplier;
        @BindView(R.id.tv_adapter_log_detail_number)
        TextView tvNumber;
        @BindView(R.id.tv_adapter_log_detail_unit)
        TextView tvStatus;

        public InventoryViewHolder(View itemView) {
            super(itemView);
        }
    }

}
